/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.delogic.simuladorbancario.main.model;

import br.com.delogic.simuladorbancario.main.exception.AcessoNegadoException;
import br.com.delogic.simuladorbancario.main.util.Acessivel;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author NB1
 */
public class Sessao {
    private static Sessao sessao;
    private final Set<Permissao> permissoes;
    
    private Sessao () {
        permissoes = new HashSet<Permissao>(Arrays.asList(Permissao.values()));
    }
    
    public static Sessao getInstance() {
        if (sessao == null) {
            sessao = new Sessao();
        }
        return sessao;
    }
    
    public void validarAcesso(Acessivel acesso) throws AcessoNegadoException {
        Permissao permissaoSolicitada = acesso.getPermissaoSoliticada();
        if(!(permissoes.contains(permissaoSolicitada))) {
            throw new AcessoNegadoException(permissaoSolicitada);
        }
    }
}